package view
{
	import map.data.Front;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.filters.GlowFilter;
	import flash.geom.Point;
	import flash.utils.ByteArray;
	
	public class FrontView extends Sprite
	{
		private var _file:File;
		private var _selected:Boolean;
		private var _loader:Loader;
		public function FrontView(file:File)
		{
			super();
			_loader = new Loader();
			_file = file;
			var fs:FileStream = new FileStream();
			fs.open(_file,FileMode.READ);
			var bytes:ByteArray = new ByteArray();
			fs.readBytes(bytes,0,fs.bytesAvailable);
			fs.close();
			_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,onComplete);
			_loader.loadBytes(bytes);
		}
		
		private function onComplete(event:Event):void
		{
			addChild(_loader);
		}
		
		public function get selected():Boolean
		{
			return _selected;
		}
		
		public function get front():Front
		{
			return new Front(_file.name,new Point(this.x,this.y));
		}
		
		public function set selected(value:Boolean):void
		{
			if(_selected == value)return;
			_selected = value;
			if(_selected)
			{
				this.filters = [new GlowFilter(0xffff00,0.8,10,10,10)];
			}else
			{
				this.filters = [];
			}
		}
		
		public function get file():File
		{
			return _file;
		}
	}
}